#include <iostream>
using namespace std;
class Person {

public:
	virtual void BuyTicket() { 
		cout << "买票-全价" << endl; 
	}
};

class Student : private Person {

public:
	virtual void BuyTicket() { 
		cout << "买票-半价" << endl; 
	}
};

class Soldier : public Person
{
public:
	virtual void BuyTicket() { 
		cout << "优先-买票" << endl;
	}
};

//多态条件
//1、虚函数重写
//2、由父类/基类指针或者引用调用虚函数

void Func(Person& p){//父类的引用调用虚函数
	p.BuyTicket();
}

int main()
{
	Person ps;
	Student st;
	Soldier sd;

	Func(ps);
	Func(st);
	Func(sd);
	return 0;
}

//void Func(Person* p) {
//	p->BuyTicket();
//}
//
//int main()
//{
//	Person* ps = new Person;
//	Student* st = new Student;
//	Soldier* sd = new Soldier;
//
//	Func(ps);
//	Func(st);
//	Func(sd);
//	return 0;
//}

